/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.C425;
import queenb.net.entitybean.C525;
import queenb.web.store.C425Store;
import queenb.web.store.C525Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class C525Controller extends QueenbController {

    private int PC525;
    private int FC425;
    private int FC475;
    private int FN100;// phan biet khach hàng
    private int CN526;// pahn biet kahch hang
    private String CV527;
    private String CV528;
    private int CN529;
    private int CN530;
    private int CN531;
    private String CV532;
    private String CV533;
    private String CV534;
    private C525Store c525Store;
    private List<C525> ccurpks_listoftabc525;
    private List<C425> ccurpks_listoftabc425;
    private List<C425> listSelectedC425 = new ArrayList<C425>();
    private List<C425> listSelectedC425FN100 = new ArrayList<C425>();
    private List<SelectItem> cbbC475 = new ArrayList<SelectItem>();
    private List<SelectItem> cbbC425 = new ArrayList<SelectItem>();
    private C425 c425 = new C425();

    public C525Controller() {
        c525Store = new C525Store();
        Object objAction = getRequest().getParameter("action");
        Object listBeanC425 = SessionProvider.getSessionMapValue("listC425");
        if (listBeanC425 == null) {
            SessionProvider.setSessionMapValue("listN100", ccurpks_listoftabc425);
        } else {
            try {
                ccurpks_listoftabc425 = (List<C425>) listBeanC425;
            } catch (Exception e) {
                ccurpks_listoftabc425 = new ArrayList<C425>();
            }
        }
        if (SessionProvider.getSessionMapValue("listSelectedExC425") != null) {
            Object listselect = SessionProvider.getSessionMapValue("listSelectedExC425");
            if (listselect == null) {
            } else {
                try {
                    listSelectedC425 = (List<C425>) listselect;
                } catch (Exception e) {
                    listSelectedC425 = new ArrayList<C425>();
                }
            }
        }

        if (SessionProvider.getSessionMapValue("listchooseFN100") != null) {
            Object listselect1 = SessionProvider.getSessionMapValue("listchooseFN100");
            if (listselect1 == null) {
            } else {
                try {
                    listSelectedC425FN100 = (List<C425>) listselect1;
                } catch (Exception e) {
                    listSelectedC425FN100 = new ArrayList<C425>();
                }
            }
        }

        if (objAction != null) {
            if (objAction.equals("addCusp100")) {
                Object f = getRequest().getParameter("p100");
                Object s = getRequest().getParameter("valueC");
                if ("false".equals(s.toString())) {
                    for (int i = 0; i < listSelectedC425.size(); i++) {
                        if (listSelectedC425.get(i).getPc425() == Integer.parseInt(f.toString())) {
                            listSelectedC425.remove(i);
                            listSelectedC425FN100.remove(i);
                            break;
                        }
                    }
                } else {
                    for (int i = 0; i < ccurpks_listoftabc425.size(); i++) {
                        if (ccurpks_listoftabc425.get(i).getPc425() == Integer.parseInt(f.toString())) {
//                            if (list.get(i).getNv105() != null && list.get(i).getNv105() != "" && list.get(i).getNv105().contains("@")) {
                            listSelectedC425.add(ccurpks_listoftabc425.get(i));
                            break;
//                            }
                        }
                    }
                }
                List<C425> listgetrros = (List<C425>) listSelectedC425;

                System.out.println("----------BAONHIEU ROW-------" + listgetrros.size());
                SessionProvider.setSessionMapValue("NUMBERPER", listgetrros.size());
                SessionProvider.setSessionMapValue("listSelectedExC425", listSelectedC425);

                System.out.println("----------BAONHIEU ROW-AAAAAAAAAAAA------" + listSelectedC425.size());
            } else if (objAction.equals("addC425")) {
                if (SessionProvider.getSessionMapValue("listSelectedExC425") != null) {
                    SessionProvider.removeSessionMapValue("listSelectedExC425");
                }
                if (SessionProvider.getSessionMapValue("listchooseFN100") != null) {
                    SessionProvider.removeSessionMapValue("listchooseFN100");
                }
            } else if (objAction.equals("addlistC425")) {
                Object f = getRequest().getParameter("p100");
                Object s = getRequest().getParameter("pc425");
                if (SessionProvider.getSessionMapValue("listSelectedExC425") != null) {
                    Object listselect = SessionProvider.getSessionMapValue("listSelectedExC425");
                    if (listselect == null) {
                    } else {
                        try {
                            listSelectedC425 = (List<C425>) listselect;
                        } catch (Exception e) {
                            listSelectedC425 = new ArrayList<C425>();
                        }
                    }
                }

                if (listSelectedC425.size() > 0) {
                    for (int i = 0; i < listSelectedC425.size(); i++) {
                        if (listSelectedC425.get(i).getPc425() == Util.parseInt(s)) {
                            c425.setPc425(Util.parseInt(s));
                            c425.setFn100(Util.parseInt(f));
                            listSelectedC425FN100.add(c425);
                            SessionProvider.setSessionMapValue("listchooseFN100", listSelectedC425FN100);
                            System.out.println("-------------ABC--------------ROW--" + listSelectedC425FN100.size());
                        }
                    }
                }
            }else if (objAction.equals("editC475")) {
                Object objPC525 = getRequest().getParameter("pc525");
                if (objPC525 != null) {
                    PC525 = Util.parseInt(objPC525);

                    List<C525> list = c525Store.ccurpks_listoftabc525(getLogin().getModule(), getLogin().getCompanyNo(), 0,0, getLogin().getUserName());
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            if (list.get(i).getPc525() == PC525) {
//                               s
//                                CN478 = list.get(i).getCn478();
//                                CN479 = list.get(i).getCn429();
//                                CN480 = list.get(i).getCn429();
//                                CV481 = list.get(i).get();
//                                CV482 = list.get(i).getCn429();
                            }
                        }
                    }
                }
            } else if (objAction.equals("deleteC525")) {
                Object objPC525 = getRequest().getParameter("pc525");
                if (objPC525 != null) {
                    PC525 = Util.parseInt(objPC525);
                    SessionProvider.setSessionMapValue("IDC525DELETE", PC525);
                }
            }
        } else {
        }

    }
    
     public void stdc_tools_stornotabc525() {
        try {
            int count = c525Store.stdc_tools_stornotabc525(Util.parseInt(SessionProvider.getSessionMapValue("IDC525DELETE")), getLogin().getUserName());
            if (count != 0) {
               
                System.out.println("-----THAM SO----");
            } else {
              
            }
        } catch (Exception e) {
        }
    }
    // onchage combobox C425

    public void actionSearch(ActionEvent ac) {
        try {
            System.out.println("---------FC425--" + FC425);
            SessionProvider.setSessionMapValue("IDFC425ONCHANGE", FC425);
        } catch (Exception e) {
        }

    }

    public void stdc_tools_inserttabc525() {
        try {
            //  System.out.println("-----THAM SO-----" + PC350 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + FC425 + "," + CN351 + "," + pvCV352 + "," + pvCV353 + "," + getLogin().getUserName());
            if (SessionProvider.getSessionMapValue("listchooseFN100") != null) {
                Object listselect = SessionProvider.getSessionMapValue("listchooseFN100");
                if (listselect == null) {
                } else {
                    try {
                        listSelectedC425FN100 = (List<C425>) listselect;
                    } catch (Exception e) {
                        listSelectedC425FN100 = new ArrayList<C425>();
                    }
                }
            }

            if (listSelectedC425FN100 != null) {
                System.out.println("--------THAM SO------" + FC475);
                int count = 0;
                for (int i = 0; i < listSelectedC425FN100.size(); i++) {
                    count = c525Store.stdc_tools_inserttabc525(PC525, listSelectedC425FN100.get(i).getPc425(), FC475, listSelectedC425FN100.get(i).getFn100(), CN526, CV527, CV528, CN529, CN530, CN531, CV532, CV533, CV534, getLogin().getUserName());
                }

                if (count != 0) {
                    showGlobalReport(true, getResourceString("success"));

                } else {
                    showGlobalReport(true, getResourceString("error"));
                }

            }

            sendRedirectUrlTab("setting.jsp?tab=header34&llinkC425=" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    /**
     * @return the PC525
     */
    public int getPC525() {
        return PC525;
    }

    /**
     * @param PC525 the PC525 to set
     */
    public void setPC525(int PC525) {
        this.PC525 = PC525;
    }

    /**
     * @return the FC425
     */
    public int getFC425() {
        return FC425;
    }

    /**
     * @param FC425 the FC425 to set
     */
    public void setFC425(int FC425) {
        this.FC425 = FC425;
    }

    /**
     * @return the FC475
     */
    public int getFC475() {
        return FC475;
    }

    /**
     * @param FC475 the FC475 to set
     */
    public void setFC475(int FC475) {
        this.FC475 = FC475;
    }

    /**
     * @return the FN100
     */
    public int getFN100() {
        return FN100;
    }

    /**
     * @param FN100 the FN100 to set
     */
    public void setFN100(int FN100) {
        this.FN100 = FN100;
    }

    /**
     * @return the CN526
     */
    public int getCN526() {
        return CN526;
    }

    /**
     * @param CN526 the CN526 to set
     */
    public void setCN526(int CN526) {
        this.CN526 = CN526;
    }

    /**
     * @return the CV527
     */
    public String getCV527() {
        return CV527;
    }

    /**
     * @param CV527 the CV527 to set
     */
    public void setCV527(String CV527) {
        this.CV527 = CV527;
    }

    /**
     * @return the CV528
     */
    public String getCV528() {
        return CV528;
    }

    /**
     * @param CV528 the CV528 to set
     */
    public void setCV528(String CV528) {
        this.CV528 = CV528;
    }

    /**
     * @return the CN529
     */
    public int getCN529() {
        return CN529;
    }

    /**
     * @param CN529 the CN529 to set
     */
    public void setCN529(int CN529) {
        this.CN529 = CN529;
    }

    /**
     * @return the CN530
     */
    public int getCN530() {
        return CN530;
    }

    /**
     * @param CN530 the CN530 to set
     */
    public void setCN530(int CN530) {
        this.CN530 = CN530;
    }

    /**
     * @return the CN531
     */
    public int getCN531() {
        return CN531;
    }

    /**
     * @param CN531 the CN531 to set
     */
    public void setCN531(int CN531) {
        this.CN531 = CN531;
    }

    /**
     * @return the CV532
     */
    public String getCV532() {
        return CV532;
    }

    /**
     * @param CV532 the CV532 to set
     */
    public void setCV532(String CV532) {
        this.CV532 = CV532;
    }

    /**
     * @return the CV533
     */
    public String getCV533() {
        return CV533;
    }

    /**
     * @param CV533 the CV533 to set
     */
    public void setCV533(String CV533) {
        this.CV533 = CV533;
    }

    /**
     * @return the CV534
     */
    public String getCV534() {
        return CV534;
    }

    /**
     * @param CV534 the CV534 to set
     */
    public void setCV534(String CV534) {
        this.CV534 = CV534;
    }

    /**
     * @return the c525Store
     */
    public C525Store getC525Store() {
        return c525Store;
    }

    /**
     * @param c525Store the c525Store to set
     */
    public void setC525Store(C525Store c525Store) {
        this.c525Store = c525Store;
    }

    /**
     * @return the ccurpks_listoftabc525
     */
    public List<C525> getCcurpks_listoftabc525() {
        try {
            ccurpks_listoftabc525 = c525Store.ccurpks_listoftabc525(getLogin().getModule(), getLogin().getCompanyNo(), FC425, FC475, getLogin().getUserName());
            return ccurpks_listoftabc525;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * @param ccurpks_listoftabc525 the ccurpks_listoftabc525 to set
     */
    public void setCcurpks_listoftabc525(List<C525> ccurpks_listoftabc525) {
        this.ccurpks_listoftabc525 = ccurpks_listoftabc525;
    }

    /**
     * @return the cbbC475
     */
    public List<SelectItem> getCbbC475() {
        ComboboxUtil combo = new ComboboxUtil();
        cbbC475 = combo.getSelectedC475Comb();
        return cbbC475;
    }

    /**
     * @param cbbC475 the cbbC475 to set
     */
    public void setCbbC475(List<SelectItem> cbbC475) {
        this.cbbC475 = cbbC475;
    }

    /**
     * @return the ccurpks_listoftabc425
     */
    public List<C425> getCcurpks_listoftabc425() {
        try {
            C425Store c425Store = new C425Store();
            if(SessionProvider.getSessionMapValue("IDFC425ONCHANGE")!=null){
                FC425 = Util.parseInt(SessionProvider.getSessionMapValue("IDFC425ONCHANGE"));
            }
            ccurpks_listoftabc425 = c425Store.ccurpks_listoftabc425(getLogin().getModule(), getLogin().getCompanyNo(), FC425, getLogin().getUserName());
            if (ccurpks_listoftabc425.size() > 0) {
                SessionProvider.setSessionMapValue("listC425", ccurpks_listoftabc425);
            }
            return ccurpks_listoftabc425;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * @param ccurpks_listoftabc425 the ccurpks_listoftabc425 to set
     */
    public void setCcurpks_listoftabc425(List<C425> ccurpks_listoftabc425) {
        this.ccurpks_listoftabc425 = ccurpks_listoftabc425;
    }

    /**
     * @return the cbbC425
     */
    public List<SelectItem> getCbbC425() {
        ComboboxUtil combo = new ComboboxUtil();
        cbbC425 = combo.getSelectedC425Comb();
        return cbbC425;
    }

    /**
     * @param cbbC425 the cbbC425 to set
     */
    public void setCbbC425(List<SelectItem> cbbC425) {
        this.cbbC425 = cbbC425;
    }
}
